package net.randomice.emf.observables.demo.extlibrary.persons.observables;

import java.util.List;
import java.util.Set;
import net.randomice.emf.observables.demo.extlibrary.Addressable;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.demo.extlibrary.persons.Person;
import net.randomice.emf.observables.demo.extlibrary.persons.PersonsFactory;
import net.randomice.emf.observables.demo.extlibrary.persons.PersonsPackage;
import net.randomice.emf.observables.demo.extlibrary.persons.Writer;
import net.randomice.emf.observables.runtime.IObservableListObject;
import net.randomice.emf.observables.runtime.ObservableSetRootObjects;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.core.databinding.observable.set.ListToSetAdapter;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable list wrapper for {@link Writer}
 * @generated
 */
public class WriterOL implements IObservableListObject<Writer> {
	public final IObservableList o;

	public WriterOL(IObservableList observableList) {
		Object type = observableList.getElementType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Writer.class.equals(type));
		o = observableList;
	}

	@SuppressWarnings("unchecked")
	public List<Writer> getList() {
		return (List<Writer>) o;
	}

	public WriterOO add(Writer object) {
		getObservableObjects();
		o.add(object);
		return (WriterOO) observableObjects.get(object);
	}

	public WriterOO addNew() {
		return add(PersonsFactory.eINSTANCE.createWriter());
	}

	private IObservableSet listToSetAdapter = null;
	public IObservableSet getObservableSet() {
		if (null == listToSetAdapter) {
			listToSetAdapter = new ListToSetAdapter(o);
		}
		return listToSetAdapter;
	}

	private ObservableSetRootObjects<Writer, WriterOO> observableObjects = null;
	@SuppressWarnings("unchecked")
	public Set<WriterOO> getObservableObjects() {
		if (null == observableObjects) {
			observableObjects = new ObservableSetRootObjects<Writer, WriterOO>(
					getObservableSet(), WriterOO.class, WriterOO.CREATOR);
		}
		return (Set<WriterOO>) observableObjects;
	}

	public IObservableMap getMapFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		if (PersonsPackage.Literals.PERSON__FIRST_NAME.equals(feature)) {
			return getFirstName();
		}
		if (PersonsPackage.Literals.PERSON__LAST_NAME.equals(feature)) {
			return getLastName();
		}
		if (PersonsPackage.Literals.WRITER__NAME.equals(feature)) {
			return getName();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableMap address = null;
	public IObservableMap getAddress() {
		if (null == address) {
			address = EMFObservables.observeMap(getObservableSet(),
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	// features from type Person

	private IObservableMap firstName = null;
	public IObservableMap getFirstName() {
		if (null == firstName) {
			firstName = EMFObservables.observeMap(getObservableSet(),
					PersonsPackage.Literals.PERSON__FIRST_NAME);
		}
		return firstName;
	}

	private IObservableMap lastName = null;
	public IObservableMap getLastName() {
		if (null == lastName) {
			lastName = EMFObservables.observeMap(getObservableSet(),
					PersonsPackage.Literals.PERSON__LAST_NAME);
		}
		return lastName;
	}

	// features from type Writer

	private IObservableMap name = null;
	public IObservableMap getName() {
		if (null == name) {
			name = EMFObservables.observeMap(getObservableSet(),
					PersonsPackage.Literals.WRITER__NAME);
		}
		return name;
	}

	// ??? many feature in list

}
